#ifndef CRENDER_H_
#define CRENDER_H_
#include "CTextureManager.h"
#include "MMath.h"
#include <windows.h>
#include <vector>
#include "CShape.h"
using namespace std;

enum SHADER_TYPE
{
	eSHADER_NONE = -1,
	eSHADER_TEXTURE = 0,
	eSHADER_DEFORM,
	eSHADER_MAX
};

class CRender
{
private:
	struct Drawable
	{
		Texture	   *pTex;
		CShape	   *pShape;
		Vec2		Pos;
		float		fZ, fRot;
		float		fAlpha;
		bool		bFlipped;
		bool		bNoTransform;

		SHADER_TYPE	shaderHandle;

		bool operator<(Drawable &Comp)
		{
			return fZ < Comp.fZ;
		}
	};

	vector<Drawable>	m_vDrawList;

	void SortDrawList();
	
	unsigned int m_handleShader[eSHADER_MAX];

	CRender() { }
	CRender(CRender &) { }
	CRender &operator=(CRender &) { }
public:
	float m_fUndoTheta;
	~CRender() { }
	
	static CRender *GetInstance();

	void InitOpenGL();
	void Resize(int nWidth, int nHeight);
	void Shutdown();

	void Render();
	void DrawTex(Texture *pTex, CShape *pShape, Vec2 Pos, float fZ = 0, float fRot = 0, bool bFlipped = false, SHADER_TYPE shaderType = eSHADER_TEXTURE, float fAlpha = 1, bool bNoTrans = false);

	bool LoadShaders(char* szVertexFileName, char* szPixelFileName, SHADER_TYPE shaderToLoad);
};

#endif